package gg.ui.application;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;

/**
 * This is the top level object that "boot-straps" all Guice injected
 * components.
 * 
 * @author Frank
 * 
 */
public class GApplication {

    private final Injector guiceInjector;

    private final GAppWindow appWindow;

    public GApplication(Module... modules) {
        guiceInjector = Guice.createInjector(modules);
        appWindow = guiceInjector.getInstance(GAppWindow.class);
    }

    public void launch() {

        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                JFrame appFrame = appWindow.getBaseFrame();

                appFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                appFrame.pack();
                appFrame.setLocationRelativeTo(null);
                appFrame.setVisible(true);
            }
        });
    }

    public GAppWindow getAppWindow() {
        return appWindow;
    }

}
